#include <cstdlib>
#include <string.h>
#include <string>
#include <cstdlib>
#include <string.h>
#include <string>
#include <cmath>
#include <iostream>
#include <ctime>

#include "model.h"
#include "pvec.h"

using namespace std;

int main(int argc, char* argv[]) {
  //test_main();
  //// load parameters from std input
  if (argc < 4) {    
    return 1;
  }  
  
  int i=1;				 // the ith argv
  if (strcmp(argv[i++], "est")==0) {
    int K0 = atoi(argv[i++]);                  // topic num
    int K1 = atoi(argv[i++]);                  // topic num
	int W = atoi(argv[i++]);
    double alpha0 = atof(argv[i++]);    // hyperparameters of p(z)
    double alpha1 = atof(argv[i++]);    // hyperparameters of p(z)
	double beta0 = atof(argv[i++]);
	double beta1 = atof(argv[i++]);
    int n_iter = atoi(argv[i++]);
	int save_step = atoi(argv[i++]);
    string dfile(argv[i++]);
    string dir(argv[i++]);
	
    cout << "==== BTM Gibbs, K0=" << K0
		 << ", K1=" << K1
		 << ", W=" << W 
		 << ", alpha0=" << alpha0
		 << ", alpha1=" << alpha1
		 << ", beta0=" << beta0
		 << ", beta1=" << beta1
		 << ", n_iter=" << n_iter 
		 << ", save_step=" << save_step 
		 << " ====" << endl;	

    // load training data from file
	clock_t start = clock();
	Model model(K0, K1, W, alpha0, alpha1, beta0, beta1, n_iter, 
				save_step, dfile, dir);
	model.run();
	clock_t end = clock();
	printf("cost %fs\n", double(end - start)/CLOCKS_PER_SEC);
  } else {
	cout << "Wrong common:" << argv[0] << " " << argv[1] << endl;
  }
}
